#include "stdafx.h"
#include "mycallback.h"
#include "Ophies.h"
#include <QDebug>


/// instance callback constructor
MyInstancesCallback::MyInstancesCallback(IrmMain *irmMain, DcmSeries *parentSeries, QObject *parent)
    : DcmInstancesCallback(parent),
      irmMain(irmMain),
      parentSeries(parentSeries)
{

}

/// instance object handler
void MyInstancesCallback::myObjectHandler(DataModel *instance)
{
    // pass
    // dynamic_cast<DcmInstance*>(instance)
}

/// instance list handler
void MyInstancesCallback::myListHandler(QList<DataModel *> *list)
{
    qDebug() << "myobject handler for DcmInstance list called";

    if (list == NULL)
    {
        qDebug() << "list object is null. ";
        return;
    }
   
}


////////////////////////////////////////////////////////////////////////////////////////////


/// series callback constructor
MySeriesCallback::MySeriesCallback(IrmMain *irmMain, DcmStudy *parentStudy, QObject *parent)
    : DcmSeriesCallback(parent),
      irmMain(irmMain),
      parentStudy(parentStudy),
      instancesCallbacks(new QList<MyInstancesCallback*>())
{
}

/// series object handler
void MySeriesCallback::myObjectHandler(DataModel *series_shadow)
{
    DcmSeries* series = dynamic_cast<DcmSeries*>(series_shadow);
    qDebug() << "myobject handler for DcmSeries called";

    if(series == NULL)
    {
        qDebug() << "DcmSeries object is null";
        return;
    }

}

/// series list handler
void MySeriesCallback::myListHandler(QList<DataModel *> *list)
{
    qDebug() << "myobject handler for series list called";

    if (list == NULL)
    {
        qDebug() << "list object is null. ";
        return;
    }
}


////////////////////////////////////////////////////////////////////////////////////////////


MyStudiesCallback::MyStudiesCallback(IrmMain* irmMain, QObject* parent)
    : DcmStudiesCallback(parent),
      irmMain(irmMain),
      seriesCallbacks(new QList<MySeriesCallback*>())
{
}

MyStudiesCallback::~MyStudiesCallback()
{
}


void MyStudiesCallback::myObjectHandler(DataModel *study_shadow)
{

}

void MyStudiesCallback::myListHandler(QList<DataModel *> *list)
{

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Class MyStudiesCallbackNested
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MyStudiesCallbackNested::MyStudiesCallbackNested(IrmMain* irmMain, COphies* pNotify, QObject *parent)
    : DcmStudiesCallback(parent),
      m_irmMain(irmMain),
      m_seriesCallbacks(new QList<MySeriesCallback*>())
{
	m_pNotify = pNotify;
}

MyStudiesCallbackNested::~MyStudiesCallbackNested()
{

}

void MyStudiesCallbackNested::myObjectHandler(DataModel *s)
{
	if( m_pNotify == NULL )
		return;
	
	m_pNotify->DownLoadCallBack( s );


	return;


	DcmStudy* study = dynamic_cast<DcmStudy*>(s);
	// example 1) all series
	QList<DcmSeries*> *series = study->getAllDcmSeries();
	if(series->size() > 0) {

		for(int i = 0; i < series->size(); i++)
		{
			QString series_uid = series->at(i)->get_series_instance_uid();

			
			// example 2) all instances
			QList<DcmInstance*> *instances = series->at(i)->getAllDcmInstances();
			if(instances->size() > 0)
			{
				for( unsigned int j = 0; j < instances->size(); j++ )
				{
					QString sop_instance_uid = instances->at(j)->get_sop_instance_uid();
					QString download_url = instances->at(i)->get_download_url();

				}
				
			} 
			else 
			{
				// not nested
				// or empty
			}
		}

	} 
	else 
	{
		// not nested
		// or empty

	}

}

void MyStudiesCallbackNested::myListHandler(QList<DataModel *> *list)
{


}

